package com.redstars.generate.controller;

import com.redstars.generate.page.PageResult;
import com.redstars.generate.result.Result;
import lombok.AllArgsConstructor;
import com.redstars.generate.service.SysMainSubTableService;
import com.redstars.generate.query.SysMainSubTableQuery;
import com.redstars.generate.vo.SysMainSubTableVo;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
* 主子表关联表
*
* @author zhouhx 
* @since 1.0.0 2022-11-08
*/
@RestController
@RequestMapping("generate/main_sub_table")
@AllArgsConstructor
public class SysMainSubTableController {
    private final SysMainSubTableService sysMainSubTableService;

    @GetMapping("page")
    public Result<PageResult<SysMainSubTableVo>> page(@Valid SysMainSubTableQuery query){
        PageResult<SysMainSubTableVo> page = sysMainSubTableService.page(query);

        return Result.ok(page);
    }

    @GetMapping("list")
    public Result<List<SysMainSubTableVo>> list(@Valid SysMainSubTableQuery query){
        List<SysMainSubTableVo> list = sysMainSubTableService.list(query);

        return Result.ok(list);
    }

    @GetMapping("{id}")
    public Result<SysMainSubTableVo> detail(@PathVariable("id") Long id){
        SysMainSubTableVo detail = sysMainSubTableService.detail(id);

        return Result.ok(detail);
    }

    @PostMapping
    public Result<String> save(@RequestBody SysMainSubTableVo vo){
        sysMainSubTableService.save(vo);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody @Valid SysMainSubTableVo vo){
        sysMainSubTableService.update(vo);

        return Result.ok();
    }

    @DeleteMapping

    public Result<List<Long>> delete(@RequestBody List<Long> idList){
        sysMainSubTableService.delete(idList);

        return Result.ok();
    }
}